package com.yuzhitong.shapi.base.net;

import com.alibaba.fastjson.JSON;
import com.yuzhitong.shapi.util.DesUtil;
import com.yuzhitong.shapi.util.LoggerUtil;

import java.util.List;

/**
 * 接口返回列表基类
 * <p>
 * 可根据实际情况设置
 *
 * @param <T> list列表中的对象泛型
 */
public class BaseListBean<T> extends BaseBean {
    private long limit;
    private long page;
    private long count;
    private List<T> data;

    public long getLimit() {
        return limit;
    }

    public void setLimit(long limit) {
        this.limit = limit;
    }

    public long getPage() {
        return page;
    }

    public void setPage(long page) {
        this.page = page;
    }

    public long getCount() {
        return count;
    }

    public void setCount(long count) {
        this.count = count;
    }

    public boolean isNoMore() {
        if (count % limit == 0) {
            return count / limit <= page;
        }
        return ((count / limit) + 1) <= page;
    }

    public List<T> getData() {
        return data;
    }

    public void setData(List<T> data) {
        this.data = data;
    }

    public void handleData(Class<T> zla) {
        if (keys == null) {
            return;
        }
        String decrypt = DesUtil.decrypt(keys);
        LoggerUtil.e("接口返回解密后数据: " + decrypt);
        data = JSON.parseArray(decrypt, zla);
    }

}
